const allEmojiReg = "/::\\)|/::~|/::B|/::\\||/:8-\\)|/::<|/::A|/::X|/::Z|/::’\\(|/::-\\||/::@|/::P|/::D|/::O|/::\\(|/::\\+|/:<b|/::Q|/::T|/:,@P|/:,@-D|/::d|/:,@o|/::g|/:\\|-\\)|/::!|/::L|/::>|/::,@|/:,@f|/::-S|/:\\?|/:,@x|/:,@@|/::8|/:,@!|/:!!!|/:xx|/:bye|/:wipe|/:dig|/:handclap|/:&-\\(|/:B-\\)|/:<@|/:@>|/::-O|/:>-\\||/:P-\\(|/::’\\||/:X-\\)|/::\\*|/:@x|/:8\\*|/:pd|/:<W>|/:beer|/:basketb|/:oo|/:coffee|/:eat|/:pig|/:rose|/:fade|/:showlove|/:heart|/:break|/:cake|/:li|/:bome|/:kn|/:footb|/:labybug|/:shit|/:moon|/:sun|/:gift|/:hug|/:strong|/:weak|/:share|/:v|/:@\\)|/:jj|/:@@|/:bad|/:lvu|/:no|/:ok|/:love|/:<L|/:jump|/:shake|/:<O>|/:circle|/:kotow|/:turn|/:skip|/:oY|/:#-0|/:hiphot|/:kiss|/:<&|/:&>";
// 解析字符串  提取表情
var chatFace = {
    fdatasm : ['微笑','嘻嘻','哈哈','可爱'],
    fdata : [
        '','/::)', '/::~', '/::B', '/::|', '/:8-)', '/::<', '/::A', '/::X', '/::Z', '/::’(', '/::-|', '/::@', '/::P', '/::D',
        '/::O', '/::(', '/::+', '/:<b', '/::Q', '/::T', '/:,@P', '/:,@-D', '/::d', '/:,@o', '/::g', '/:|-)', '/::!',
        '/::L',
        '/::>', '/::,@', '/:,@f', '/::-S', '/:?', '/:,@x', '/:,@@', '/::8', '/:,@!', '/:!!!', '/:xx', '/:bye', '/:wipe',
        '/:dig', '/:handclap', '/:&-(', '/:B-)', '/:<@', '/:@>', '/::-O', '/:>-|', '/:P-(', '/::’|', '/:X-)', '/::*',
        '/:@x',
        '/:8*', '/:pd', '/:<W>', '/:beer', '/:basketb', '/:oo', '/:coffee', '/:eat', '/:pig', '/:rose', '/:fade',
        '/:showlove',
        '/:heart', '/:break', '/:cake', '/:li', '/:bome', '/:kn', '/:footb', '/:labybug', '/:shit', '/:moon', '/:sun',
        '/:gift', '/:hug',
        '/:strong', '/:weak', '/:share', '/:v', '/:@)', '/:jj',
        '/:@@', '/:bad', '/:lvu', '/:no', '/:ok', '/:love', '/:<L', '/:jump', '/:shake', '/:<O>', '/:circle',
        '/:kotow', '/:turn', '/:skip', '/:oY', '/:#-0', '/:hiphot', '/:kiss', '/:<&', '/:&>'
    ],
    extractEmoji : function (obs) {
        let reg = new RegExp(/<img.*?(?:>|\/>)/gi);
        let arr = obs.match(reg);
        if(!arr){
            return obs;
        }
        let newStr = this.replaceEmoji(arr, obs);
        return newStr;
    },
    extractIndex:function (obj) {
        let arr = obj.split(".");
        let arr2 = arr[0].split("f/");
        let emojiIndex = this.fdata[arr2[1]];
        return emojiIndex;
    },
    replaceEmoji:function (a,str) {
        let z = str;
        let len = a.length;
        for (let i = 0; i < len; i++) {
            let emojiIndex = this.extractIndex(a[i]);
            let emojiReg = new RegExp(a[i]);
            z = z.replace(emojiReg, emojiIndex);
        }
        return z;
    },
    restoreEmoji:function (a) {
        let arr = a.match(allEmojiReg);
        if(!arr){return a;}
        for(var i in chatFace.fdata){
            if(chatFace.fdata[i] == arr[0]){
                var img = '<i><img src="../../image/im/emotion/Expression_' + i + '.png"></i>';
                //var img = '<img src="../../image/im/emotion1/' + i + '.gif">';
                a = a.replace(chatFace.fdata[i],img);
                return chatFace.restoreEmoji(a);
            }
        }
    },
};
